from django.db import models
from django.contrib.auth.models import AbstractUser,UserManager as _UserManager
# Create your models here.


# 以下为新增部分，重写父类源码,实现email可以为空
class UserManager(_UserManager):
    def create_superuser(self, username,  password, email=None,**extra_fields):
        super().create_superuser(username=username, password=password, email=email)


class Users(AbstractUser):
    """
    add mobile、email_active field to Django users modules
    """
    # 以下为新增部分
    REQUIRED_FIELDS = ['mobile']
    objects = UserManager()

    mobile = models.CharField(
        max_length=11,
        unique=True,
        help_text="手机号",
        verbose_name="手机号",
        error_messages={'unique': '此手机号已注册'}
    )
    email_active = models.BooleanField(default=False, verbose_name='邮箱验证状态')

    class Meta:
        db_table = 'tb_users'   # 指明数据库表名
        verbose_name = '用户'   # 在admin站点中显示的名字
        verbose_name_plural = verbose_name    # 显示的复数名称

    def __str__(self):
        return self.username




